home *** CD-ROM | disk | FTP | other *** search
- /*
- * $RCSfile: openLogDisk.c,v $
- * $Revision: 1.1.1.1 $
- * $Date: 1996/05/04 21:55:50 $
- */
- /**********************************************************************
- * EXODUS Database Toolkit Software
- * Copyright (c) 1991 Computer Sciences Department, University of
- * Wisconsin -- Madison
- * All Rights Reserved.
- *
- * Permission to use, copy, modify and distribute this software and its
- * documentation is hereby granted, provided that both the copyright
- * notice and this permission notice appear in all copies of the
- * software, derivative works or modified versions, and any portions
- * thereof, and that both notices appear in supporting documentation.
- *
- * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
- * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.
- * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
- * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
- *
- * The EXODUS Project Group requests users of this software to return
- * any improvements or extensions that they make to:
- *
- * EXODUS Project Group
- * c/o David J. DeWitt and Michael J. Carey
- * Computer Sciences Department
- * University of Wisconsin -- Madison
- * Madison, WI 53706
- *
- * or exodus@cs.wisc.edu
- *
- * In addition, the EXODUS Project Group requests that users grant the
- * Computer Sciences Department rights to redistribute these changes.
- **********************************************************************/
-
- #include "sysdefs.h"
- #include "ess.h"
- #include "checking.h"
- #include "trace.h"
- #include "error.h"
- #include "list.h"
- #include "pool.h"
- #include "tid.h"
- #include "io.h"
- #include "lock.h"
- #include "object.h"
- #include "msgdefs.h"
- #include "thread.h"
- #include "semaphore.h"
- #include "latch.h"
- #include "link.h"
- #include "lsn.h"
- #include "bf.h"
- #include "log.h"
- #include "volume.h"
- #include "openlog.h"
- #include "disk.h"
- #include "trans.h"
- #include "logrecs.h"
- #include "log_intfuncs.h"
- #include "log_extfuncs.h"
- #include "bf_extfuncs.h"
- #include "io_extfuncs.h"
- #include "disk_funcs.h"
- #include "recover_extfuncs.h"
- #include "thread_globals.h"
- #include "log_globals.h"
- #include "io_globals.h"
-
-
- extern int errno;
- extern FILE* sm_ErrorStream;
-
- /* set in server/ options handling */
- VOLID LogVolid;
-
-
- void
- openLogDisk ()
-
- {
- VOLREC *volRec;
- BOOL performRecovery;
- int minLogSpace;
-
- TRACE(TR_LOG, TR_LEVEL_1);
-
- /*
- * initialize the log link
- */
- LogLink.id = 1000;
- LogLink.flags = LINK_FREE;
- LogLink.linkClass = CL_DISK;
- initializeListElement( &(LogLink.list), (char *) &LogLink );
- initializeList( &(LogLink.tcbList) );
- initializeList( &(LogLink.volList) );
- initializeList( &(LogLink.transList) );
-
-
- /*
- * Set up space for holding list of mounted volumes to
- * add to the checkpoint record
- */
- CheckpointVolumes = (VOLIDNAME*) malloc(NumVolumes * sizeof(*CheckpointVolumes));
- if (CheckpointVolumes == NULL) {
- SM_ERROR(TYPE_STOP, esmMALLOCFAILED);
- }
-
- /*
- * No checkpoint has had its dirty page table flushed yet
- */
- LastFlushedCheckpoint.offset = NULL_LSN;
- LastFlushedCheckpoint.wrapCount = 0;
- OldestDirtyPageLSN = LastFlushedCheckpoint;
-
- /*
- * mount the volume: first we need to get the volume id from
- * the file.
- */
- if ((volRec = io_MountLogVolume(LogVolid)) == NULL) {
-
- fprintf(sm_ErrorStream, "SERVER ERROR: Cannot mount the log volume: %d\n", LogVolid);
- SM_ERROR(TYPE_STOP, Active->errno);
- return;
- }
- #ifdef DEBUG
- if (!(volRec->volflags & VOL_RAWDEV)) {
- fprintf(sm_ErrorStream, "NOTE: log volume is not a raw disk, so fsyncs will be performed\n");
- }
- #endif
-
- /*
- * link the new disk to the log link
- */
- linkVolume( &LogLink, volRec );
-
- /*
- * check to see if there is a log on this disk
- */
- if (volRec->header->logFileAddr != NULLPID) {
- int readPages;
- int writePages;
-
- /* Decide if we will recover the log or regenerate it */
- performRecovery = RecoverLog && volRec->header->dismountEndOfLog.wrapCount != NULL_LOG_WRAP_COUNT;
-
- /*
- * Open the log file.
- * The log write buffer group should have enough pages
- * to support writing pages in MAX_IO_LIST chunks.
- * The log read buffer needs only a small amount since pages
- * are rarely re-read and we have no prefetching.
- */
- writePages = (MAX_IO_LIST+MAX_IO_LIST/2)*RAISETWO(volRec->header->logFileBlock2size - MIN_PAGE2SIZE);
- readPages = (MAX_IO_LIST/2)*RAISETWO(volRec->header->logFileBlock2size - MIN_PAGE2SIZE);
-
- if (openLogFile(volRec, writePages, readPages, performRecovery)) {
-
- /*
- * signal any waiters
- */
- notify( &(volRec->tcbList), esmFAILURE, Active->errno);
-
- /*
- * return indication that mount failed
- */
- SM_ERROR(TYPE_STOP, esmINTERNAL);
- return;
- }
-
- /*
- * Make sure the log is large enough
- */
- minLogSpace = 2 * MAX_LOGREC_LEN + /* 2 checkpoints */
- 2 * MAX_LOGREC_LEN + /* 1 record and undo */
- LOG_SLACK;
- if (OpenLog.fileBytes < minLogSpace) {
- fprintf(sm_ErrorStream, "SERVER ERROR: log volume is too small\n");
- fprintf(sm_ErrorStream, "\tMake sure it is formatted with at least %d log pages\n", minLogSpace/OpenLog.pageSize + 1);
- SM_ERROR(TYPE_STOP, esmLOGTOOSMALL);
- }
-
- /* see if the log needs to be regenerated */
- if (performRecovery) {
-
- /*
- * recover the log file
- */
- recoverLog();
-
- } else {
-
- if (volRec->header->dismountEndOfLog.wrapCount == NULL_LOG_WRAP_COUNT) {
- fprintf(sm_ErrorStream, "SERVER: log volume is new -- automatically regenerating the log\n");
- }
-
- CheckpointsEnabled = FALSE; // do not allow checkpoints
-
- /*
- * regenerate the log
- */
- if (regenLog( &OpenLog )) {
-
- /*
- * signal any waiters
- */
- notify( &(volRec->tcbList), esmFAILURE, Active->errno);
-
- /*
- * return indication that mount failed
- */
- SM_ERROR(TYPE_STOP, esmINTERNAL);
- return;
- }
-
- CheckpointsEnabled = TRUE; // allow checkpoints
- }
-
- /* record current end of log for use by clients */
- OpenLog.nextValidLSN.wrapCount = OpenLog.wrapCount;
- OpenLog.nextValidLSN.offset =
- FIRST_LSN_ON_PAGE(OpenLog.tailLSN, (&OpenLog));
-
-
- } else {
-
- /*
- * Invalid logging volume
- */
- fprintf(sm_ErrorStream, "SERVER ERROR: volume %d is not a log volume.\n", LogVolid);
- SM_ERROR(TYPE_STOP, esmBADLOGVOLUME);
- return;
- }
-
- return;
- }
-